package com.weixing.mall.provider.controller.admin;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.annotation.SysLog;
import com.weixing.mall.core.enums.OperateEnum;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.AuthUtil;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.provider.api.model.vo.AgentInfoVo;
import com.weixing.mall.provider.model.dto.AgentInfoEditDto;
import com.weixing.mall.provider.service.IAgentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 代理商相关Api
 *
 * @author  kfc
 * @since 1.0
 */
@Validated
@RestController
@RequestMapping("agent/info")
public class AgentInfoController extends BaseController {

    @Autowired
    private IAgentInfoService agentInfoService;

    /**
     * 保存代理商身份信息
     *
     * @param dto   参数
     * @return      代理id
     */
    @PostMapping("")
    @NoRepeatSubmit
    @SysLog(type = OperateEnum.S, desp = "编辑代理商身份信息")
    public Result<Long> save( AgentInfoEditDto dto) {
        SysAuth auth = AuthUtil.getSysExt();
        return ResultUtil.success(agentInfoService.saveInfo(dto,auth.getUid()));
    }

    /**
     * 代理商身份信息(回显)
     * @param agentId  代理id
     * @return         代理详情
     */
    @GetMapping("/{agentId}")
    public Result<AgentInfoVo> get(@PathVariable Long agentId) {
        AgentInfoVo agentInfoVo = agentInfoService.selectByAgentId(agentId);
        return ResultUtil.success(agentInfoVo);
    }

}
